<template>
  <el-table
    :data="goodsList"
    stripe
    border
    style="width: 100%">

    <!-- 索引 -->
    <el-table-column type="index" label="#" align="center" />

    <!-- 参数名称 -->
    <el-table-column prop="goods_name" label="商品名称" align="center"/>

    <!-- 商品价格 -->
    <el-table-column prop="goods_price" label="商品价格(元)" width="110px" align="center"/>
    
     <!-- 商品重量 -->
    <el-table-column prop="goods_weight" label="商品重量" width="80px" align="center"/>

     <!-- 创建时间 -->
    <el-table-column prop="add_time" label="创建时间" width="180px" align="center">
      <template v-slot="data">
        {{ data.row.add_time | timerFormat }}
      </template>
    </el-table-column>

    <!-- 操作 -->
    <el-table-column label="操作" width="130px" align="center">
      <template v-slot="data">
        <el-button-com  size="mini" icon="el-icon-edit"/>
        <el-button-com  size="mini" btnType="danger" icon="el-icon-delete" 
        @click.native="delItemById(data.row)"/>
      </template>
    </el-table-column>

  </el-table>
</template>

<script>
// 组件
  import ElButtonCom from '@/components/common/ElButtonCom';
// 网络
  import { delGoodById } from '@/network/goodListRequest';

export default {
  props: {
    goodsList: Array
  },
  methods: {
    async delItemById(row) { // 删除操作
      // goods_id
      // console.log(row);
      const resConfirm = await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err => err);
      
      // 判断用户执行的操作
      if (resConfirm !== 'confirm') {
        return this.$message('取消删除');
      }
      // 执行删除
      this.delGoodByIdRequest(row.goods_id);

    },
    async delGoodByIdRequest(id) { // 删除接口函数
      const { meta } = await delGoodById(id);
      if (meta.status !== 200) {
        console.log(meta);
        return this.$message.error(meta.msg);
      }
      this.$bus.$emit('getGoodList'); // 刷新数据
      return this.$message.success(meta.msg);
    }
  },
  components: {
    ElButtonCom
  }
}
</script>

<style lang="scss" scoped>

</style>